package com.onefish.toolkit;

import cn.hutool.core.date.DateUtil;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.cron.timingwheel.SystemTimer;
import cn.hutool.cron.timingwheel.TimerTask;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
//@EnableScheduling
//@ConditionalOnProperty(prefix = "enable", name = "scheduled", havingValue = "true")
public class SchedulingConfig {
    public static void main(String[] args) {
        //延时任务执行
        SystemTimer systemTimer = new SystemTimer();
        systemTimer.start();
        System.out.println("延时任务开始时间：" + DateUtil.now());
        systemTimer.addTask(
                new TimerTask(
                        () -> {
                            System.out.println("延时任务执行时间：" + DateUtil.now());
                            CronUtil.schedule("0 */2 * * * *", (Task) () -> System.out.println("我是定时任务1，我开始执行业务逻辑了..." + DateUtil.now()));
                            CronUtil.setMatchSecond(true);
//                            CronUtil.start();
//                            CronUtil.schedule("*/5 * * * * *", (Task) () -> System.out.println("我是定时任务2，我开始执行业务逻辑了..." + DateUtil.now()));
//                            CronUtil.setMatchSecond(true);
//                            CronUtil.start();
                        }
                        , 5000));

    }
}